#include <bits/stdc++.h>
// 2025/02/07
// tag: 
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

int n, m, t, f[301][301];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> t;
    memset(f, 0x3f, sizeof(f));
    for (int i = 1, s, e, h; i <= m; i++)
        cin >> s >> e >> h, f[s][e] = min(f[s][e], h);
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                f[i][j] = min(f[i][j], max(f[i][k], f[k][j]));
    for (int i = 1, s, e; i <= t; i++){
        cin >> s >> e;
        if (f[s][e] == 0x3f3f3f3f)
            cout << -1 << endl;
        else
            cout << f[s][e] << endl;
    }
    return 0;
}